#include "mtcmain.h"
#include "ui_mtcmain.h"
#include "qextserialport.h"
#include "qextserialenumerator.h"
#include "QtGui"

MTCmain::MTCmain(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MTCmain)
{
    ui->setupUi(this);
    loadPorts();
}

MTCmain::~MTCmain()
{
    delete ui;
}

void MTCmain::loadPorts(void)
{
    QextSerialPort *serial;
    QextSerialEnumerator serialEnum;
    serial=new QextSerialPort();
    //serialEnum=new QextSerialEnumerator();
    QList<QextPortInfo> portsList=serialEnum.getPorts();
    int ctemp=portsList.count();

    if (ctemp<1)
    {
        QMessageBox msgBox;
        msgBox.setText("No serial ports are available.");
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.exec();
    }
    else
    {
        QString portM;
        for (ctemp;ctemp>0;ctemp--)
        {
            portM=portsList.value(ctemp).portName;
            //ui->lb->setText(ui->lb->text()+" " +portM);
            ui->lw->insertItem(0,portM);
        }
//        serial->setBaudRate(BAUD9600);
//        serial->setParity(PAR_NONE);
//        serial->setDataBits(DATA_8);
//        serial->setStopBits(STOP_1);
//        serial->setFlowControl(FLOW_OFF);
//        serial->setQueryMode(QextSerialPort::EventDriven);
//        serial->setPortName("/dev/ttyS0");
   }
}
